package cn.wit.summit.chwan.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import cn.wit.summit.chwan.R;
import cn.wit.summit.chwan.utils.ForumUtil;


/**
 * Created by pengsk on 2016/9/2.
 */
public class VipView extends LinearLayout {
    Context context;

    public VipView(Context context) {
        super(context);
        this.context = context;

    }

    public VipView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    public VipView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
    }

    /*public void setVipData(int vip, int sVip) {
        ImageView tip = this;
        tip.setMaxHeight(context.getResources().getDimensionPixelOffset(R.dimen.app_list_margin));
        tip.setMaxWidth(context.getResources().getDimensionPixelOffset(R.dimen.app_list_margin));
        if (sVip > 0) {
            tip.setBackgroundResource(R.drawable.vip_gold_back);
            tip.setImageResource(getMumberRes(sVip));
        } else if (vip > 0) {
            tip.setBackgroundResource(R.drawable.vip_red_back);
        } else {
            tip.setVisibility(View.GONE);
        }
        invalidate();
    }*/

    public void setVipData(int vip, int sVip) {
        this.removeAllViewsInLayout();
        ImageView tip = new ImageView(context);
        this.addView(tip);
        LayoutParams params = (LayoutParams) tip.getLayoutParams();
//        params.height = context.getResources().getDimensionPixelOffset(R.dimen.activity_horizontal_margin);
//        params.width = context.getResources().getDimensionPixelOffset(R.dimen.activity_horizontal_margin);
        params.gravity= Gravity.CENTER_VERTICAL;
        params.height = context.getResources().getDimensionPixelOffset(R.dimen.wdp24);
        params.width = context.getResources().getDimensionPixelOffset(R.dimen.wdp24);
        tip.setImageResource(android.R.color.transparent);
        if (sVip > 0) {
            this.setVisibility(View.VISIBLE);
            tip.setVisibility(View.VISIBLE);
            tip.setImageResource(getMumberRes(sVip));
        } else if (vip > 0) {
            this.setVisibility(View.VISIBLE);
            tip.setVisibility(View.VISIBLE);
            tip.setImageResource(R.drawable.vip_red_back);
            ForumUtil.goWelfareVip(tip);
        } else {
            this.setVisibility(View.GONE);
            tip.setVisibility(View.GONE);
        }
        invalidate();
    }

    public void setVipDataForUserCenter(int vip, int sVip) {
        this.removeAllViewsInLayout();
        ImageView tip = new ImageView(context);
        this.addView(tip);
        LayoutParams params = (LayoutParams) tip.getLayoutParams();
        params.gravity= Gravity.CENTER_VERTICAL;
        params.height = context.getResources().getDimensionPixelOffset(R.dimen.wdp24);
        params.width = context.getResources().getDimensionPixelOffset(R.dimen.wdp24);
        if (sVip > 0) {
            tip.setImageResource(getMumberRes(sVip));
        } else if (vip > 0) {
            tip.setImageResource(R.drawable.vip_red_back);
            ForumUtil.goWelfareVip(tip);
        } else {
            tip.setImageResource(R.drawable.vip_defalut_image);
        }
        invalidate();
    }
    public void setVipDataForUserCenter(int vip, int sVip,boolean isDdefalueGod) {
        this.removeAllViewsInLayout();
        ImageView tip = new ImageView(context);
        this.addView(tip);
        LayoutParams params = (LayoutParams) tip.getLayoutParams();
        params.gravity= Gravity.CENTER_VERTICAL;
        params.height = context.getResources().getDimensionPixelOffset(R.dimen.wdp24);
        params.width = context.getResources().getDimensionPixelOffset(R.dimen.wdp24);
        if (sVip > 0) {
            tip.setImageResource(getMumberRes(sVip));
        } else if (vip > 0) {
            tip.setImageResource(R.drawable.vip_red_back);
        } else {
            tip.setImageResource(R.drawable.vip_defalut_image_god);
        }
        invalidate();
    }

    private int getMumberRes(int number) {
        switch (number) {
            case 1:
                return R.drawable.vip_gold_number_1;
            case 2:
                return R.drawable.vip_gold_number_2;

            case 3:
                return R.drawable.vip_gold_number_3;

            case 4:
                return R.drawable.vip_gold_number_4;

            case 5:
                return R.drawable.vip_gold_number_5;

            case 6:
                return R.drawable.vip_gold_number_6;

            case 7:
                return R.drawable.vip_gold_number_7;

            case 8:
                return R.drawable.vip_gold_number_8;

            case 9:
                return R.drawable.vip_gold_number_9;

        }
        return R.drawable.vip_gold_number_1;
    }
}
